﻿using System;
using System.Collections.Generic;
using System.Threading;
using sscore;

using sscore.Requests;
using sscore.Utils;

namespace DM4
{
    public partial class DM4
    {        
        public string GenerateEntityId(string code)
        {
            lock (Locker)
            {
                Thread.Sleep(1);
                DateTime dt = DateTime.Now;
                return String.Format("{0}-{1}{2}{3}-{4}{5}{6}-{7}", code, dt.Year, dt.Month.ToString().PadLeft(2, '0'),
                                     dt.Day.ToString().PadLeft(2, '0'), dt.Hour.ToString().PadLeft(2, '0'),
                                     dt.Minute.ToString().PadLeft(2, '0'), dt.Second.ToString().PadLeft(2, '0'),
                                     dt.Millisecond.ToString().PadLeft(3, '0'));
            }
        }

        private string GetModuleFileNameByCode(string moduleCode, bool shortName = false)
        {
            if (_modules.ContainsKey(moduleCode.ToUpper()))
            {
                return shortName ? _modules[moduleCode.ToUpper()].ShortFileName : _modules[moduleCode.ToUpper()].FileName;
            }
            return "";
        }

        private void BeginFunction(string functionName)
        {
            if (_debug)
            {
                string message = String.Format("Begin function [{0}]", functionName);
                _sysLog.WriteLog(message, MessageType.Cool);
             
                //DMN_Log
                WriteLog(logType:LogType.System, message:message, messType:MessageType.Begin);
            }
        }

        private void EndFunction(string functionName)
        {
            if (_debug)
            {
                string message = String.Format("End function [{0}]", functionName);
                _sysLog.WriteLog(String.Format("End function [{0}]", message), MessageType.Cool);
                
                //DMN_Log
                WriteLog(logType: LogType.System, message: message, messType: MessageType.End);
            }
        }
    }
}
